package com.timoon.component.panel.jqgrid.action;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;

import com.googlecode.wicket.jquery.ui.Options;
import com.googlecode.wicket.jquery.ui.form.button.AjaxButton;
import com.timoon.app.utils.HttpServletUtil;
import com.timoon.component.behavior.jbox.AbstractJboxBehavior;
import com.timoon.component.panel.jqgrid.JqGridPanel;
import com.timoon.component.panel.jqgrid.JqGridService;

/**
 * 删除按钮
 * @author Administrator
 *
 */
public class DelButton extends AjaxButton {
	private static final long serialVersionUID = 764658262412401927L;
	private String key;
	private JqGridService service;
	/**
	 * 
	 * @param id
	 * @param selector	table标签的id
	 * @param service
	 */
	public DelButton(String id,JqGridPanel mainPanel) {
		super(id);
		// TODO Auto-generated constructor stub
		this.key=mainPanel.getKey();
		this.service=mainPanel.getService();
		
		if(!mainPanel.isButtonVisible(JqGridPanel.DELETE_BUTTON_ENABLE)){
			this.setVisible(false);
		}
		
		this.add(new AbstractJboxBehavior("", "click", new Options()));
	}
	@Override
	protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
		// TODO Auto-generated method stub
		super.onSubmit(target, form);
		
		
		String url=HttpServletUtil.getBasePath()+"/controller/jqgrid/onDelete?gridKey="+key;
		target.appendJavaScript("myjbox.beforeDelete('#grid-"+key+"','"+url+"')");
	}
	/**
	 * 响应删除操作
	 * @param deleteIds
	 */
	public void onDelete(String deleteIds) {
		// TODO Auto-generated method stub
		this.service.deleteByIds(deleteIds);
	}

}
